package com.code.monitor.service.impl;

import com.code.monitor.conditions.MemoryRuntimeCondition;
import com.code.monitor.model.CacheManager;
import com.code.monitor.model.MachineInfo;
import com.code.monitor.service.MachineService;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Conditional(MemoryRuntimeCondition.class)
@Service
public class MemoryMachineServiceImpl implements MachineService {
    @Override
    public void addMachineInfo(MachineInfo machineInfo) {
        CacheManager.addMachineInfo(machineInfo);
    }

    @Override
    public void delMachineInfo(String ip) {
        CacheManager.delMachineInfo(ip);
    }

    @Override
    public Collection<MachineInfo> queryAllMachine() {
        return CacheManager.getMachineInfoList();
    }

    @Override
    public MachineInfo queryMachineByIP(String ip) {
        return CacheManager.getMachineInfo(ip);
    }
}
